package com.zlikun.lq.l_62;

import java.util.Date;

public class Student implements Cloneable {
	
	private String name;
	private Date birthDay;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Date getBirthDay() {
		return birthDay;
	}
	public void setBirthDay(Date birthDay) {
		this.birthDay = birthDay;
	}
	@Override
	public Student clone() {
		Student stu = new Student();
		stu.name = this.name;
		//stu.birthDay = this.birthDay;//浅拷贝
		stu.birthDay = (Date) this.birthDay.clone();//深拷贝
		return stu;
	}
	
	public static void main(String[] args) {
		Student stu = new Student();
		stu.setName("zhangsan");
		stu.setBirthDay(new Date());
		Student stuBak = stu.clone();
		stuBak.setName("lisi");
		// stuBak.setBirthDay(new Date(2011, 1, 1));   错误实例：用new Date等于将stuBak中birthDay从引用1变成引用2，而不是在原有的基础进行改变
		stuBak.getBirthDay().setHours(0);  //改变stuBak的birthDay的小时
		
		//System.out.println("浅拷贝输出stu:"+stu.getName()+","+stu.getBirthDay());  //浅拷贝输出stu:zhangsan,Tue Jan 16 00:20:25 CST 2018
		System.out.println("深拷贝输出stu:"+stu.getName()+","+stu.getBirthDay()); //深拷贝输出stu:zhangsan,Tue Jan 16 22:24:11 CST 2018
	}
	
}
